package com.hxkj.controller;

import com.hxkj.domain.po.FriendlyLink;
import com.hxkj.service.FriendlyLinkService;
import com.platform.common.dispatcher.util.ResultStructUtils;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * 友情链接控制器
 * <p>
 * Created by chenfangzhou on 2018/5/15.
 */
@RestController
@RequestMapping("/friendlink")
public class FriendlyLinkController {

    private static final Logger LOGGER = LoggerFactory.getLogger(FriendlyLinkController.class);

    @Autowired
    private FriendlyLinkService friendlyLinkService;


    /**
     * 获取友情链接列表
     *
     * @param parameterDataStruct
     * @return 翻页数据
     * @throws Exception
     */
    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    public Callable<ResultPageStruct<FriendlyLink>> getFriendlyLinkList(@RequestBody ParameterDataStruct<FriendlyLink> parameterDataStruct) throws Exception {
        return () -> ResultStructUtils.buildResultPageStruct(friendlyLinkService.getFriendlyLinkList
                (parameterDataStruct.getData() == null ? new FriendlyLink() : parameterDataStruct.getData(), parameterDataStruct.getPageTo()), "param=value");
    }

    /**
     * 获取单个友情链接
     *
     * @param friendlyLink
     * @return FriendlyLink
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<FriendlyLink>> getFriendlyLink(@RequestBody FriendlyLink friendlyLink) throws Exception {
        return () -> friendlyLinkService.getFriendlyLink(friendlyLink);
    }

    /**
     * 新增友情链接
     *
     * @param friendlyLink
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public ResultMessageStruct saveFriendlyLink(@RequestBody FriendlyLink friendlyLink) throws Exception {
        return friendlyLinkService.saveFriendlyLink(friendlyLink);
    }

    /**
     * 删除友情链接
     *
     * @param friendlyLink
     * @throws Exception
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public ResultMessageStruct deleteFriendlyLink(@RequestBody FriendlyLink friendlyLink) throws Exception {
        return friendlyLinkService.deleteFriendlyLink(friendlyLink);
    }

    /**
     * 更新友情链接
     *
     * @param friendlyLink
     * @throws Exception
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public ResultMessageStruct updateFriendlyLink(@RequestBody FriendlyLink friendlyLink) throws Exception {
        return friendlyLinkService.updateFriendlyLink(friendlyLink);
    }

    /**
     * 获取友情链接列表,不带分页
     *
     * @param friendlyLink
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getListNoPage", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public List<FriendlyLink> getFriendlyLinkListNoPage(@RequestBody FriendlyLink friendlyLink) throws Exception {
        return friendlyLinkService.getFriendlyLinkListNoPage(friendlyLink);
    }

}
